package com.face.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.face.common.Result;
import com.face.common.ResultCode;
import com.face.service.FileUploadService;

@RestController
@RequestMapping("/upload")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("/image")
    public Result uploadImage(@RequestBody Map<String,byte[]> map){
        String imagePath =  fileUploadService.uploadImage(map.get("featureImageData"));
        if(imagePath == null || imagePath.equals("")){
            return Result.failure(ResultCode.UPLOAD_IMAGE_FAIL);
        }

        Map<String, String> data = new HashMap<>();
        data.put("imagePath", imagePath);
        return Result.success(ResultCode.UPLOAD_IMAGE_SUCCESS,data);
    }
}
